import ajax from './ajax'

// 登录
export const reqLogin = (username, password) => {
  return ajax({
    url: 'login',
    method: 'post',
    data: {
      username,
      password
    }
  })
}

// 左侧菜单权限
export const reqMenuList = () => {
  return ajax({
    method: 'get',
    url: 'menus'
  })
}

// 获取用户数据列表
export const reqUserList = (query, pagenum, pagesize) => {
  return ajax({
    method: 'get',
    url: 'users',
    params: {
      query,
      pagenum,
      pagesize
    }
  })
}

// 修改用户状态
export const reqUpdateStatus = (uId, type) => {
  return ajax({
    method: 'put',
    url: `users/${uId}/state/${type}`,
  })
}

// 添加用户
export const reqAddUser = (username, password, email, mobile) => {
  return ajax({
    method: 'post',
    url: 'users',
    data: {
      username,
      password,
      email,
      mobile
    }
  })
}

// 编辑用户
export const reqUpdateUser = (id, email, mobile) => {
  return ajax({
    method: 'put',
    url: `users/${id}`,
    data: {
      email,
      mobile
    }
  })
}

// 删除用户
export const reqDeleteUser = (id) => {
  return ajax({
    method: 'delete',
    url: `users/${id}`
  })
}

// 获取列表权限列表
export const reqPermissionList = () => {
  return ajax({
    method: 'get',
    url: 'rights/list'
  })
}

// 获取树状权限列表
export const reqPermissionTree = () => {
  return ajax({
    method: 'get',
    url: 'rights/tree'
  })
}

// 获取所有的角色列表
export const reqRoleList = () => {
  return ajax({
    method: 'get',
    url: 'roles'
  })
}

// 更新用户的角色
export const reqUpdateRolePower = (id, rid) => {
  return ajax({
    method: 'put',
    url: `users/${id}/role`,
    data: {
      rid
    }
  })
}

// 添加角色
export const reqAddRole = (roleName, roleDesc) => {
  return ajax({
    method: 'post',
    url: 'roles',
    data: {
      roleName,
      roleDesc
    }
  })
}

// 编辑角色
export const reqUpdateRole = (id, roleName, roleDesc) => {
  return ajax({
    method: 'put',
    url: `roles/${id}`,
    data: {
      roleName,
      roleDesc
    }
  })
}

// 删除角色
export const reqDeleteRole = (id) => {
  return ajax({
    method: 'delete',
    url: `roles/${id}`
  })
}

// 删除角色指定权限
export const reqDeleteRoleById = (roleId, rightId) => {
  return ajax({
    method: 'delete',
    url: `roles/${roleId}/rights/${rightId}`
  })
}

// 角色授权
export const reqUpdateRoleAuth = (roleId, rids) => {
  return ajax({
    method: 'post',
    url: `roles/${roleId}/rights`,
    data: {
      rids
    }
  })
}

// 商品分类
export const reqGoodList = (type, pagenum, pagesize) => {
  return ajax({
    method: 'get',
    url: 'categories',
    params: {
      type,
      pagenum,
      pagesize
    }
  })
}

// 获取父级分类的数据列表【一级&二级】
export const reqParentdGoodList = (type) => {
  return ajax({
    method: 'get',
    url: 'categories',
    params: {
      type
    }
  })
}

// 获取所有分类的数据
export const reqAllCateList = (type) => {
  return ajax({
    method: 'get',
    url: 'categories',
    params: {
      type
    }
  })
}


// 添加分类
export const reqAddCategory = (cat_pid, cat_name, cat_level) => {
  return ajax({
    method: 'post',
    url: 'categories',
    data: {
      cat_pid,
      cat_name,
      cat_level
    }
  })
}

// 修改分类
export const reqEditCategory = (id, cat_name) => {
  return ajax({
    method: 'put',
    url: `categories/${id}`,
    data: {
      cat_name
    }
  })
}

// 删除分类
export const reqDeleteCategory = (id) => {
  return ajax({
    method: 'delete',
    url: `categories/${id}`
  })
}

// 获取列表参数
export const reqParamsList = (id, sel) => {
  return ajax({
    method: 'get',
    url: `categories/${id}/attributes`,
    params: {
      sel
    }
  })
}

// 添加动态参数或者静态属性
export const reqAddParams = (id, attr_name, attr_sel) => {
  return ajax({
    method: 'post',
    url: `categories/${id}/attributes`,
    data: {
      attr_name,
      attr_sel
    }
  })
}


// 编辑提交参数
export const reqEditParams = (id, attrId, attr_name, attr_sel) => {
  return ajax({
    method: 'put',
    url: `categories/${id}/attributes/${attrId}`,
    data: {
      attr_name,
      attr_sel
    }
  })
}

// 删除参数
export const reqDeleteParams = (id, attrId, attr_name, attr_sel) => {
  return ajax({
    method: 'delete',
    url: `categories/${id}/attributes/${attrId}`,
    data: {
      attr_name,
      attr_sel
    }
  })
}

// 添加动态参数或者静态属性的可选项
export const reqAddOptionalParams = (id, attrId, attr_name, attr_sel, attr_vals) => {
  return ajax({
    method: 'put',
    url: `categories/${id}/attributes/${attrId}`,
    data: {
      attr_name,
      attr_sel,
      attr_vals
    }
  })
}

// 获取商品列表数据
export const reqGoodsList = (query, pagenum, pagesize) => {
  return ajax({
    method: 'get',
    url: 'goods',
    params: {
      query,
      pagenum,
      pagesize
    }
  })
}

// 上传图片
export const reqUpload = (file) => {
  return ajax({
    method: 'post',
    url: 'upload',
    data: {
      file
    }
  })
}

// 添加商品
export const reqAddGood = (goodsObj) => {
  return ajax({
    method: 'post',
    url: 'goods',
    data: goodsObj
  })
}

// 根据id查询商品
export const reqGoodId = (id) => {
  return ajax({
    method: 'get',
    url: `goods/${id}`
  })
}

// 编辑商品列表
export const reqEditGood = (id, goodsObj) => {
  return ajax({
    method: 'put',
    url: `goods/${id}`,
    data: goodsObj
  })
}

// 删除商品列表
export const reqDeleteGood = (id) => {
  return ajax({
    method: 'delete',
    url: `goods/${id}`
  })
}

// 订单数据列表
export const reqGetOrderList = (queryInfo) => {
  return ajax({
    method: 'get',
    url: 'orders',
    params: queryInfo
  })
}

// 查看物流信息
export const reqTraceInfo = (id) => {
  return ajax({
    method: 'get',
    url: `/kuaidi/${id}`
  })
}

// 获取图表数据
export const reqReport = () => {
  return ajax({
    method: 'get',
    url: 'reports/type/1'
  })
}
